var prefix = "/admin/dept";
var listData = []

$(function () {
  listData = []
  var addFlag = permissions.sys_dept_add
  var editFlag = permissions.sys_dept_edit
  var deleteFlag = permissions.sys_dept_del
  //没有新增权限的话删除新增按钮
  if (!addFlag){
    $('#addBtn').remove()
  }
  var options = {
    code: "deptId",
    parentCode: "parentId",
    uniqueId: "deptId",
    // rootIdValue: JSON.parse(session.get('userInfo')).deptId,
    method: 'post',
    expandAll: false,
    expandFirst: false,
    url: prefix + "/list",
    createUrl: "/pages/sysadm/dept/deptEdit",
    updateUrl: "/pages/sysadm/dept/deptEdit",
    removeUrl: prefix + "/{id}",
    modalName: "部门",
    columns: [
      {
        field: 'selectItem',
        radio: true
      },
      {
        title: '部门名称',
        field: 'name',
        width: '20%',
        formatter: function (value, row, index) {
          return "<span class='colMoreStyle' title='" + value + "'>" + value + "</span>";
        },
      },
      {
        title: '部门编码',
        field: 'deptCode',
        width: '20%'
      },
      {
        field: 'sort',
        title: '排序',
        width: '20%',
        align: "left"
      },
      {
        field: 'createTime',
        title: '创建时间',
        width: '20%',
        align: "left"
      },
      {
        title: '操作',
        width: '20%',
        align: "left",
        formatter: function (value, row, index) {
          var actions = [];
          if (editFlag) {
            actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.deptId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
          }
          if (deleteFlag){
            actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.deptId + '\')"><i class="fa fa-trash"></i>删除</a>');
          }
          return actions.join('');
        }
      }]
  };
  $.treeTable.init(options);

});
